<?php
/* avec register globals à ON
if(!isset($nb1)) {$nb1="";}
if(!isset($nb2)) {$nb2="";}
if(!isset($resultat)) {$resultat="";}
if(!isset($action)) {$action="";}
 * */
 
// avec register globals à OFF et métode POST
if(!isset($_POST["nb1"])) {$nb1="";} else {$nb1 = $_POST["nb1"];}
if(!isset($_POST["nb2"])) {$nb2="";} else {$nb2 = $_POST["nb2"];}
if(!isset($_POST["resultat"])) {$resultat="";} else {$resultat = $_POST["resultat"];}
if(!isset($_POST["cb_op"])) {$cb_op="";} else {$cb_op = $_POST["cb_op"];}
if(!isset($_POST["action"])) {$action="";} else {$action = $_POST["action"];}




if ($action==1) {
    echo "OK";

$resultat=0;
if($cb_op==1) {
    $resultat = $nb1 + $nb2;
} elseif ($cb_op==2) {
    $resultat = $nb1 - $nb2;
} elseif ($cb_op==3) {
    $resultat = $nb1 * $nb2;   
} else {
    $resultat = $nb1 / $nb2;   
}
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Calculatrice</title>
        <link href="bootstrap/css/bootstrap.css" type="text/css" rel="stylesheet">
        <style>
            .form-control {
                width: 150px;
            }
        </style>
    </head>
    <body>
        <?php
        // put your code here
        ?>
        <form id="form1" name="form1" action="" method="post">
            <div><input type="number" id="nb1" name="nb1" value="<?php echo $nb1; ?>" class="form-control"></div>
            <div><input type="number" id="nb2" name="nb2" value="<?php echo $nb2; ?>" class="form-control"></div>
            <div>
                <select id="cb_op" name="cb_op" class="form-control">
                <option value='1'>+</option>
                <option value='2'>-</option>
                <option value='3'>x</option>
                <option value='4'>:</option>
                </select>
            </div>
            <div><button type="submit" id="bouton" class = "btn btn-success"><span class="glyphicon glyphicon-list-alt"></span>Calculer</button></div>
            <div><input type="number" id="resultat" name="resultat" class="form-control" value="<?php echo $resultat; ?>" readonly="readonly"></div>
            <input type="hidden" name="action" id="action" value="1">
        </form>
        
    </body>
</html>
